import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

import org.junit.*;

/**
 * @author joncaddey
 * @version 1.0
 */
public class TerritoryAdjacenciesReaderTest {

	private static final String NAME_A = "Territory A";
	private static final String NAME_B = "Territory B";
	private static final String NAME_C = "Territory C";

	private Territory terr_a;
	private Territory terr_b;
	private Territory terr_c;

	private TerritoryAdjacenciesReader my_reader;
	private List<Territory> my_territories;

	@Before
	public void setup() {
		my_reader = new TerritoryAdjacenciesReader();
		my_territories = new ArrayList();
		terr_a = new State(NAME_A);
		terr_b = new State(NAME_B);
		terr_c = new State(NAME_C);

		Collections.addAll(my_territories, new Territory[] { terr_a, terr_b,
				terr_c });
	}

	/**
	 * Unrecognized Territory at start!
	 */
	@Test(expected = IllegalArgumentException.class)
	public void testUnrecognizedTerritoryRead() {
		my_reader.read(new Scanner("TerritoryC"), my_territories);
	}

	/**
	 * Unrecognized Territory as neighbor!
	 */
	@Test(expected = IllegalArgumentException.class)
	public void testSecondUnrecognizedTerritoryRead() {
		my_reader.read(new Scanner(NAME_A + "\nTerritoryC"), my_territories);
	}

	/**
	 * Making A a neighbor of B automatically makes B a neighbor of A.
	 */
	@Test
	public void testRecipricalRead() {
		my_reader.read(new Scanner(NAME_A + "\n" + NAME_B + "\n" + NAME_C),
				my_territories);
		assertTrue("Should have been neighbor", terr_c.isNeighbor(terr_a));
	}

	/**
	 * Can read adjacencies of multiple territories.
	 */
	@Test
	public void testMultipleRead() {
		my_reader.read(new Scanner(NAME_A + "\n" + NAME_B + "\n\n" + NAME_B + "\n" + NAME_C),
				my_territories);
		assertTrue("Missing B as neighbor of A", terr_b.isNeighbor(terr_a));
		assertTrue("Missing C as neighbor of B", terr_c.isNeighbor(terr_b));
	}

}
